<template>
  <div class="forgetPassword">
    <div class="login-box">
      <h4 class="title">忘记密码</h4>
      <div class="js-sign-in-container">
        <div class="form">
          <div class="username public">
            <input type="text" v-model.trim="phone" placeholder="请输入手机号" maxlength="11">
            <i class="iconfont iconyunongtongqingshurushoujihaoma"></i>
          </div>
          <div class="public">
            <input class="code" v-model.trim="code" placeholder="请填写短信验证码">
            <i class="iconfont iconcodev"></i>
            <span class="getCode" :class="[btnValue>=0?'activeColor':'']" @click="getCode()">{{btnValue}}</span>
          </div>
          <div class="password public">
            <input type="password" v-model.trim="password" placeholder="请输入新密码">
            <i class="iconfont iconmima1"></i>
          </div>
          <button class="sign-in-button" @click="confirm()">确定</button>
        </div>
      </div>
      <div class="goback" @click="loginJump()">返回登录</div>
    </div>
  </div>
</template>
<script>
import base from "@/assets/js/base";
import { requestApiPost } from "../api/api";
import { reqRep } from "../report/reqReport";
import { resRep } from "../report/resReport";
export default {
  name: "forgetPassword",
  data() {
    return {
      phone: "",
      code: "",
      password: "",
      btnValue: "获取"
    };
  },
  methods: {
    getCode() {
      if (!this.phone) {
        this.$message.warning("请填写手机号");
        return;
      }
      if (this.btnValue == "获取" || this.btnValue == "重发") {
        this.getCodeRequest();
        this.btnValue = 60;
        var setTime = setInterval(() => {
          if (this.btnValue > 0) {
            this.btnValue--;
          } else {
            this.btnValue = "重发";
            clearInterval(setTime);
          }
        }, 1000);
      }
    },
    //获取短信验证码
    getCodeRequest() {
      if (!base.isPoneAvailable(this.phone)) {
        this.$message.warning("手机号格式不正确");
        return;
      }
      let data = { phone: this.phone };
      base.getAjax("/bizUser/insertAuthCode", data).then(res => {
        if (res.data.code == 1) {
        } else {
          this.$message.error(res.data.message);
        }
      });
    },
    confirm() {
      if (!this.phone || !this.password) {
        this.$message.warning("信息不完整");
        return;
      }
      if (!this.code) {
        this.$message.warning("请填写短信验证码");
        return;
      }
      var data = {
        type: "2",
        phone: this.phone,
        smsCode: this.code,
        password: this.password
      };

      base.postAjax("/bizUser/updatePassWord", data).then(res => {
        if (res.data.code == 1) {
          this.$message.success(res.data.message);
          setTimeout(() => {
            this.$router.push("login");
          }, 500);
        } else {
          this.$message.error(res.data.message);
        }
      });
    },
    loginJump() {
      this.$router.push("login");
    }
  },
  created() {},
  mounted() {}
};
</script>
<style scoped>
.forgetPassword {
  min-height: 750px;
  min-width: 600px;
  text-align: center;
  font-size: 16px;
  background-color: #f3f7f9;
}
.forgetPassword .login-box {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 440px;
  margin-top: -189.5px;
  margin-left: -220px;
  padding: 20px 50px 30px;
  background-color: #fff;
  border-radius: 4px;
  box-sizing: border-box;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  vertical-align: middle;
  display: inline-block;
}
.forgetPassword .login-box .title {
  margin: 0 auto 20px;
  color: #333;
  padding: 10px;
  font-size: 20px;
}

.public {
  position: relative;
  width: 100%;
  height: 50px;
  margin-bottom: 12px;
  vertical-align: middle;
}

.getCode {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 60px;
  text-align: center;
  height: 30px;
  font-size: 14px;
  line-height: 30px;
  border-radius: 4px;
  background: #13cb6e;
  color: #fff;
  cursor: pointer;
}
.activeColor {
  background: #ccc;
}
.forgetPassword .login-box .js-sign-in-container .form input {
  border-radius: 4px;
}
input {
  height: 50px;
  width: 100%;
  padding: 4px 12px 4px 35px;
  box-sizing: border-box;
  outline: none;
  background-color: #f3f7f9;
  border: 1px solid rgba(0, 0, 0, 0.04);
}
i {
  position: absolute;
  top: 14px;
  left: 10px;
  width: 18px;
  height: 25px;
  line-height: 25px;
  font-size: 18px;
  color: #969696;
}
.forgetPassword .sign-in-button {
  line-height: 1.2;
  padding: 12px 20px;
  height: auto;
  width: 100%;
  font-size: 16px;
  font-weight: 600;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  outline: none;
  display: block;
  color: #fff;
  background: #13cb6e;
  box-shadow: 0 3px 6px rgba(19, 203, 110, 0.25);
}
.forgetPassword .it-operate {
  justify-content: space-between;
  margin: 15px 0;
  font-size: 15px;
  color: #969696;
}

.forgetPassword .it-operate .remember input[type="checkbox"] {
  vertical-align: middle;
  cursor: pointer;
}
.forgetPassword .it-operate .remember label {
  margin-left: 5px;
  vertical-align: middle;
  cursor: pointer;
}
.forgetPassword .it-operate .forget {
  cursor: pointer;
}
.tip {
  position: relative;
  z-index: 3;
  height: 100%;
  width: 100%;
  background: #fff;
}
.tip .warn {
  margin: 100px auto;
  height: 100px;
  width: 900px;
  font-size: 24px;
  text-align: center;
  color: #fff;
  line-height: 80px;
  background-image: url("../assets/img/bg_tip.jpg");
  background-size: 100% 100%;
  background-repeat: no-repeat;
}
.goback {
  font-size: 14px;
  margin-top: 18px;
  text-align: left;
  cursor: pointer;
  color: #999;
}
footer {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 60px;
  line-height: 60px;
  font-size: 12px;
  text-align: center;
}
footer a {
  color: #999;
}
</style>
